{{!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!

Included on Cython unions to retrieve the current value of the union and stick
it in the self.value variable.

}}{{#field:reference?}}{{!
}}if not deref(self._cpp_obj).get_{{field:py_name}}():
    self.value = None
else:
    {{! Use an aliasing constructor since the object we're returning is still
        managed by the top-level object, possible via a unique_ptr }}
    self.value = {{> types/CythonPythonType}}.create(__reference_shared_ptr({{!
      }}deref(deref(self._cpp_obj).get_{{field:py_name}}()), self._cpp_obj)){{!
}}{{/field:reference?}}{{!
}}{{^field:reference?}}{{!
}}{{#type:bool?}}{{!
  }}self.value = <bint>(deref(self._cpp_obj).get_{{field:py_name}}()){{!
}}{{/type:bool?}}{{!
}}{{#type:byte?}}{{!
  }}self.value = deref(self._cpp_obj).get_{{field:py_name}}(){{!
}}{{/type:byte?}}{{!
}}{{#type:i16?}}{{!
  }}self.value = deref(self._cpp_obj).get_{{field:py_name}}(){{!
}}{{/type:i16?}}{{!
}}{{#type:i32?}}{{!
  }}self.value = deref(self._cpp_obj).get_{{field:py_name}}(){{!
}}{{/type:i32?}}{{!
}}{{#type:i64?}}{{!
  }}self.value = deref(self._cpp_obj).get_{{field:py_name}}(){{!
}}{{/type:i64?}}{{!
}}{{#type:double?}}{{!
  }}self.value = deref(self._cpp_obj).get_{{field:py_name}}(){{!
}}{{/type:double?}}{{!
}}{{#type:float?}}{{!
  }}self.value = deref(self._cpp_obj).get_{{field:py_name}}(){{!
}}{{/type:float?}}{{!
}}{{#type:string?}}{{!
  }}self.value = bytes(deref(self._cpp_obj).get_{{field:py_name}}()).decode('UTF-8'){{!
}}{{/type:string?}}{{!
}}{{#type:binary?}}{{!
  }}{{#type:iobuf?}}{{!
    }}self.value =  __iobuf.from_unique_ptr({{!
      }}deref(self._cpp_obj).get_{{field:py_name}}().clone()){{!
  }}{{/type:iobuf?}}{{!
  }}{{^type:iobuf?}}{{!
    }}self.value = deref(self._cpp_obj).get_{{field:py_name}}(){{!
  }}{{/type:iobuf?}}{{!
}}{{/type:binary?}}{{!
}}{{#type:enum}}{{!
  }}self.value = translate_cpp_enum_to_python({{!
    }}{{> types/CythonPythonType}}, {{!
    }}<int>deref(self._cpp_obj).get_{{field:py_name}}()){{!
}}{{/type:enum}}{{!
}}{{#type:struct?}}{{!
}}self.value = {{> types/CythonPythonType}}.create({{!
  }}make_shared[{{> types/CythonCppType}}]({{!
  }}deref(self._cpp_obj).get_{{field:py_name}}())){{!
}}{{/type:struct?}}{{!
}}{{#type:container?}}{{!
}}self.value = {{> types/CythonPythonType}}.create({{!
  }}make_shared[{{> types/CythonCppType}}]({{!
  }}deref(self._cpp_obj).get_{{field:py_name}}())){{!
}}{{/type:container?}}{{!
}}{{/field:reference?}}
